package com.movitech.mobile.cz.base.modules.entity;

import java.io.Serializable;
import java.util.Date;
import com.baomidou.mybatisplus.annotations.TableField;
import com.baomidou.mybatisplus.annotations.TableId;
import com.baomidou.mybatisplus.annotations.TableLogic;
import com.baomidou.mybatisplus.enums.IdType;
import com.movitech.mobile.cz.base.common.util.DateUtils;
import com.movitech.mobile.cz.base.common.util.IdGenUtils;
import com.movitech.mobile.cz.base.common.util.StringUtils;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.experimental.Accessors;

@Data
@Accessors(chain = true)
@ApiModel
public class BaseEntity implements Serializable {
	
	private static final long serialVersionUID = 6971211452515045320L;

	/**
     * 主键
     */
    @TableId(value = "id", type = IdType.ID_WORKER_STR)
    @ApiModelProperty(value = "主键,ID_WORKER策略")
	private String id;

    /**
     * 创建人id
     */
    @TableField("create_by")
    @TableLogic
    @ApiModelProperty(value = "创建人id")
    private String createBy;

    /**
     * 创建日期
     */
    @TableField("create_date")
    @TableLogic
    @ApiModelProperty(value = "创建日期")
    private Date createDate;

    /**
     * 更新人id
     */
    @TableField("update_by")
    @TableLogic
    @ApiModelProperty(value = "更新人id")
    private String updateBy;

    /**
     * 更新日期
     */
    @TableField("update_date")
    @TableLogic
    @ApiModelProperty(value = "更新日期")
    private Date updateDate;
   
    /**
     * 备注
     */
    @TableField("remarks")
    @TableLogic
    @ApiModelProperty(value = "备注")
    private String remarks;
    
    /**
     * 逻辑删除标志位
     */
    @TableField("del_flag")
    @TableLogic
    @ApiModelProperty(value = "逻辑删除标志位")
    private Integer delFlag;

//    /**
//     * 更新时候的乐观锁标志位
//     */
//    @TableField("lock_version")
//    @Version
//    @ApiModelProperty(value = "更新时候的乐观锁标志位")
//    private Integer lockVersion;

    public void setBaseFeilds(String userId,String remarks,Integer delFlag,boolean isSetCreator){
        if(isSetCreator){
            this.setCreateBy(userId);
            this.setCreateDate(DateUtils.getNow());
        }
        if(StringUtils.isEmpty(this.getId())){
            this.setId(IdGenUtils.uuid());
        }
        this.setUpdateBy(userId);
        this.setUpdateDate(DateUtils.getNow());
        if(StringUtils.isNotEmpty(remarks)){
            this.setRemarks(remarks);
        }
        this.setDelFlag(delFlag);

    }



}
